package com.example.redis.test;/*
   
/**
* @program: demo
*
* @description: 测试redis
*
* @author: kk
*
* @create: 2020-02-04 15:57
**/

import com.example.mybites.test.model.AppleMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@EnableAutoConfiguration
@RequestMapping("/redisTest")
public class RedisTestController {
    @Resource
    private RedisTemplate redisTemplate;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RequestMapping("/redis")
    public String index() {
        /*    //字符串
        stringRedisTemplate.opsForValue().set("mm", "哈哈哈");
        String value = stringRedisTemplate.opsForValue().get("mm");

        //对象（对象要实现Serializable,即对象要被序列化）
        AppleMessage am=new AppleMessage();
        am.setId("7777777");
        am.setMessage("这是一个对象");
        redisTemplate.opsForValue().set("kkk",am);
        AppleMessage  ap=(AppleMessage)    redisTemplate.opsForValue().get("kkk");
        System.out.println(ap.getMessage());*/
        AppleMessage am=new AppleMessage();
        am.setId("99999");
        am.setMessage("这也是一个对象");
        //
     Long  a=  redisTemplate.opsForList().leftPush("template_query",am);
        AppleMessage aas=  (AppleMessage) redisTemplate.opsForList().leftPop("template_query");
    return aas.getId();
      //  return value;
    }

}
